package com.rbac.web.db;

import com.baomidou.mybatisplus.annotation.TableName;
import com.rbac.web.model.Role;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

/**
 * @author gengaoliu
 */
@Getter
@Setter
@ToString
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@TableName("role")
@EqualsAndHashCode(callSuper = true)
public class RoleDO extends BaseDO {
  private String name;
  private String code;
  private Boolean disabled;
  private String description;

  public static RoleDO from(Role role) {
    return RoleDO.builder()
        .id(role.getId())
        .createBy(role.getCreatedBy())
        .createTime(role.getCreatedTime())
        .updateBy(role.getUpdatedBy())
        .updateTime(role.getUpdatedTime())
        .name(role.getName())
        .code(role.getCode())
        .disabled(role.getDisabled())
        .description(role.getDescription())
        .build();
  }

  public Role to() {
    return Role.builder()
        .id(this.getId())
        .createdBy(this.getCreateBy())
        .createdTime(this.getCreateTime())
        .updatedBy(this.getUpdateBy())
        .updatedTime(this.getUpdateTime())
        .name(this.getName())
        .code(this.getCode())
        .disabled(this.getDisabled())
        .description(this.getDescription())
        .build();
  }
}
